package ro.isdc.navigator.retriever.jdbc.strategy;

/**
 * Oracle strategy for computing the paginated SQL.
 * 
 * @author Andrei Chirila / ISDC! Romania
 * @version 1.0
 * @date Jul 9, 2009
 */
public class OracleComputePaginatedSQLStrategy extends AbstractComputePaginatedSQLStrategy {
  
  /**
   * {@inheritDoc}
   */
  protected String buildPaginatedSQL(final String SQL, final SQLType sqlType) {
    StringBuffer buffer = new StringBuffer(
        "select * from ( select rownum rownumber_, row_.* from ( ");
    buffer.append(SQL);
    buffer.append(" ) row_) where");
    if (SQLType.INDEXED == sqlType) {
      buffer.append(" rownumber_ > ?  and rownumber_ <= ?");
    } else {
      buffer.append(" rownumber_ > :start and rownumber_ <= :end");
    }
    return buffer.toString();
  }

}
